package com.xth8013.demo.mvc.action;

import com.xth8013.demo.mvc.service.IDemoService;
import com.xth8013.thspring.webmvc.annotation.THAutowired;
import com.xth8013.thspring.webmvc.annotation.THController;
import com.xth8013.thspring.webmvc.annotation.THRequestMapping;
import com.xth8013.thspring.webmvc.annotation.THRequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * description:
 *
 * @author tianhua.xie（tianhua.xie@ucarinc.com）
 * @version 1.0
 * @date 2018/8/2 14:32
 */
@THController
@THRequestMapping("/demo")
public class DemoAction {

    @THAutowired
    private IDemoService demoServiceImpl;

    @THRequestMapping("/query.json")
    public void query(HttpServletRequest request, HttpServletResponse response,@THRequestParam("name") String name){

        try {
            String s = demoServiceImpl.get(name);
            response.getWriter().write(s);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    @THRequestMapping("/add.json")
    public void add(HttpServletRequest request, HttpServletResponse response, @THRequestParam("a") Integer a,@THRequestParam("b") Integer b) {

        try {
            response.getWriter().write(a+b);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    @THRequestMapping("/remove.json")
    public void remove(HttpServletRequest request, HttpServletResponse response,@THRequestParam("id") Integer id){

        try {
            response.getWriter().write(id);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
